// 操作日志服务层

package service

import (
	"admin-go-api/api/dao"
	"admin-go-api/api/entity"
	"admin-go-api/common/result"
	"github.com/gin-gonic/gin"
)

type ISysOperationLogService interface {
	GetSysOperationLog(c *gin.Context, PageSize, PageNum int, UserName, BeginTime, EndTime string)
	DeleteOperationLogById(c *gin.Context, dto entity.SysOperationLogIdDto)
	BatchDeleteSysOperationLog(c *gin.Context, dto entity.DelSysOperationLogDto)
	CleanSysOperationLog(c *gin.Context)
}

type SysOperationLogServiceImpl struct {
}

// GetSysOperationLog 分页查询操作日志
func (s *SysOperationLogServiceImpl) GetSysOperationLog(c *gin.Context, PageSize, PageNum int,
	UserName, BeginTime, EndTime string) {
	if PageSize <= 0 {
		PageSize = 10
	}
	if PageNum <= 0 {
		PageNum = 1
	}
	sysOperationLog, count := dao.GetSysOperationLog(PageSize, PageNum, UserName, BeginTime, EndTime)
	result.Success(c, map[string]interface{}{"total": count, "pageSize": PageSize, "pageNum": PageNum, "list": sysOperationLog})
}

// DeleteOperationLogById 根据id删除操作日志
func (s *SysOperationLogServiceImpl) DeleteOperationLogById(c *gin.Context, dto entity.SysOperationLogIdDto) {
	dao.DeleteOperationLogById(dto)
	result.Success(c, true)
}

// BatchDeleteSysOperationLog 批量删除操作日志
func (s *SysOperationLogServiceImpl) BatchDeleteSysOperationLog(c *gin.Context, dto entity.DelSysOperationLogDto) {
	dao.BatchDeleteSysOperationLog(dto)
	result.Success(c, true)
}

// CleanSysOperationLog 清空操作日志
func (s *SysOperationLogServiceImpl) CleanSysOperationLog(c *gin.Context) {
	dao.CleanSysLoginInfo()
	result.Success(c, true)
}

var sysOperationLogService = SysOperationLogServiceImpl{}

func SysOperationLogService() ISysOperationLogService {
	return &sysOperationLogService
}
